package com.ruoyi.system.service.impl;

import java.text.SimpleDateFormat;
import java.util.*;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.mapper.*;
import com.ruoyi.system.service.IMaterialService;
import com.ruoyi.system.service.IWatehouseMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.service.IWarehousingService;

import javax.annotation.Resource;

/**
 * 入库单Service业务层处理
 *
 * @author ruoyi
 * @date 2021-05-08
 */
@Service
public class WarehousingServiceImpl implements IWarehousingService {
    @Autowired
    private WarehousingMapper warehousingMapper;
    @Autowired
    private PurchaseRecordMapper purchaseRecordMapper;

    @Autowired
    private PurchaseMapper purchaseMapper;
    @Resource
    private ProjectsMapper projectsMapper;

    @Resource
    private com.ruoyi.system.mapper.WatehouseMaterialMapper WatehouseMaterialMapper;

    @Resource
    private com.ruoyi.system.mapper.WarehouseDetailMapper WarehouseDetailMapper;
    @Resource
    private MaterialMapper materialMapper;


    /**
     * 查询入库单
     *
     * @param id 入库单ID
     * @return 入库单
     */
    @Override
    public Warehousing selectWarehousingById(Long id) {

        Warehousing warehousing = warehousingMapper.selectWarehousingById(id);

        if (null != warehousing.getPurId()) {
            Purchase purchase = purchaseMapper.selectPurchaseByPurId(warehousing.getPurId());
            warehousing.setProName(purchase.getProName());
            warehousing.setProNumber(purchase.getProNumber());
            return warehousing;
        }
        return warehousing;
    }

    /**
     * 查询入库单列表
     *
     * @param warehousing 入库单
     * @return 入库单
     */
    @Override
    public List<Warehousing> selectWarehousingList(Warehousing warehousing) {
        return warehousingMapper.selectWarehousingList(warehousing);
    }

    /**
     * 新增入库单
     *
     * @param warehousing 入库单
     * @return 结果
     */
    @Override
    public int insertWarehousing(Warehousing warehousing) {

        int result = warehousingMapper.insertWarehousing(warehousing);
        if (null != warehousing.getPurchaseRecords()) {
            for (int i = 0; i < warehousing.getPurchaseRecords().size(); i++) {
                if (warehousing.getOprType() == 0) {
                    PurchaseRecord purchaseRecord = warehousing.getPurchaseRecords().get(i);
                    //入库
                    MaterialThree materialThree = new MaterialThree();
                    materialThree.setmName(purchaseRecord.getmName());
                    materialThree.setmModel(purchaseRecord.getmModel());
                    materialThree.setmUnit(purchaseRecord.getmUnit());
                    Long mid = materialMapper.selectMId(materialThree);
                    //查看材料表是否有这种材料
                    if (null == mid) {
                        //给材料表添加材料
                        materialMapper.insertMatOnly(materialThree);
                        purchaseRecord.setmId(materialThree.getmId());
                    } else {
                        purchaseRecord.setmId(mid);
                    }
                    if (warehousing.getType() == 0) {
                        purchaseRecord.setMdInType(0);
                    }
                    if (warehousing.getType() == 1) {
                        purchaseRecord.setMdInType(1);
                    }
                    warehousing.getPurchaseRecords().get(i).setWarehousingId((warehousing.getId()));
                } else if (warehousing.getOprType() == 1) {
                    //出库
                    warehousing.getPurchaseRecords().get(i).setOutingId((warehousing.getId()));
                }
                purchaseRecordMapper.insertPurchaseRecord(warehousing.getPurchaseRecords().get(i));
            }
        }
        return result;

    }

    /**
     * 修改入库单
     *
     * @param warehousing 入库单
     * @return 结果
     */
    @Override
    public int updateWarehousing(Warehousing warehousing) {
        //判断是否是生成的
        if (null != warehousing.getPurId()) {
            Purchase purchase = new Purchase();
            purchase.setProName(warehousing.getProName());
            purchase.setProNumber(warehousing.getProNumber());
            purchase.setId(warehousing.getPurId());
            //先去修改purchase中的项目名称
            purchaseMapper.updatePurchase(purchase);
            //生成的赋值为空
            warehousing.setProName("");
            warehousing.setProNumber("");
            warehousingMapper.updateWarehousing(warehousing);
        } else {
            //不是生成正常修改
            warehousingMapper.updateWarehousing(warehousing);
        }
        List<PurchaseRecord> purchaseRecords = warehousing.getPurchaseRecords();
        //修改里面的材料
        //入库
        if (warehousing.getOprType() == 0) {
            if (null != purchaseRecords && purchaseRecords.size() > 0) {
                for (int i = 0; i < purchaseRecords.size(); i++) {
                    if (purchaseRecords.get(i).getId() != null) {
                        //证明是原有的材料，做修改
                        purchaseRecordMapper.updatePurchaseRecord(purchaseRecords.get(i));
                    } else {
                        //没有的材料插入
                        //判断是何种类型入库
                        if (warehousing.getType() == 0 || warehousing.getType() == 1) {
                            //甲供乙购材料新插入
                            //证明这是个新添材料
                            MaterialThree materialThree = new MaterialThree();
                            materialThree.setmName(purchaseRecords.get(i).getmName());
                            materialThree.setmModel(purchaseRecords.get(i).getmModel());
                            materialThree.setmUnit(purchaseRecords.get(i).getmUnit());
                            Long mid = materialMapper.selectMId(materialThree);
                            //查看材料表是否有这种材料
                            if (null == mid) {
                                //给材料表添加材料
                                materialMapper.insertMatOnly(materialThree);
                                purchaseRecords.get(i).setmId(materialThree.getmId());
                            } else {
                                purchaseRecords.get(i).setmId(mid);
                            }
                        }
                        if (warehousing.getType() == 0) {
                            purchaseRecords.get(i).setMdInType(0);
                        }
                        if (warehousing.getType() == 1) {
                            purchaseRecords.get(i).setMdInType(1);
                        }
                        //设置外键
                        purchaseRecords.get(i).setWarehousingId(warehousing.getId());
                        //插入材料
                        purchaseRecordMapper.insertPurchaseRecord(purchaseRecords.get(i));
                    }
                }
            }
        }
        //出库
        if (warehousing.getOprType() == 1) {
            if (null != purchaseRecords && purchaseRecords.size() > 0) {
                for (int i = 0; i < purchaseRecords.size(); i++) {
                    if (purchaseRecords.get(i).getId() != null) {
                        //证明是原有的材料，做修改
                        purchaseRecordMapper.updatePurchaseRecord(purchaseRecords.get(i));
                    } else {
                        //新加的材料
                        //设置外键
                        purchaseRecords.get(i).setOutingId(warehousing.getId());
                        purchaseRecordMapper.insertPurchaseRecord(purchaseRecords.get(i));
                    }
                }
            }
        }
        return 1;
    }


    /**
     * 删除出入库单信息
     *
     * @param id 入库单ID
     * @return 结果
     */
    @Override
    public int deleteWarehousingById(Warehousing warehousing) {
        if (warehousing.getOprType() == 0) {
            //入库删除
            Long id = warehousing.getId();
            //先判断材料有没有入库
            if (warehousingMapper.selectInState(id) <= 0) {
                //先动小表
                //先判断是不是采购生成的
                if (null == warehousing.getPurId()) {
                    //证明不是生成的直接删除
                    warehousingMapper.deleteAllMat(id);
                } else {
                    //如果是生成的话，把状态改成0即可
                    warehousingMapper.updateAllWareId(id);

                }
                //再删大表
                warehousingMapper.deleteWarehousingById(id);
                //修改采购单状态
                if (null != warehousing.getPurId()) {
                    warehousingMapper.updatePurchaseInState(warehousing.getPurId());
                }

                return 1;
            } else {
                return 0;
            }
        }
        if (warehousing.getOprType() == 1) {
            //出库删除
            Long id = warehousing.getId();
            //先判断材料有没有入库
            if (warehousingMapper.selectOutState(id) <= 0) {
                //先动小表
                //先判断是不是采购生成的
                if (null == warehousing.getPurId()) {
                    //证明不是生成的直接删除
                    warehousingMapper.deleteAllOutMat(id);
                } else {
                    //如果是生成的话，把状态改成0即可
                    warehousingMapper.updateAllOutId(id);

                }
                //再删大表
                warehousingMapper.deleteWarehousingById(id);
                //修改采购单状态
                if (null != warehousing.getPurId()) {
                    warehousingMapper.updatePurchaseOutState(warehousing.getPurId());
                }

                return 2;
            } else {
                return 3;
            }
        }
          return 4;
    }



    @Override
    public List<Warehousing> selectQueryWarehousing(Warehousing warehousing) {
        List<Warehousing> warehousingList1 = warehousingMapper.selectWarehousing(warehousing);
//        List<Warehousing> warehousingList = warehousingMapper.selectWarehouList(warehousing);
//        ArrayList<Warehousing> warehou = new ArrayList<>();
//        for (int i = 0; i < warehousingList1.size(); i++) {
//            warehou.add(warehousingList1.get(i));
//
//        }
//        for (int i = 0; i < warehousingList.size(); i++) {
//            warehou.add(warehousingList.get(i));
//        }
        if (warehousing.getOprType()==0) {
            for (int i = 0; i < warehousingList1.size(); i++) {
                    //证明还有出完
                if (warehousingMapper.selectStateIn(warehousingList1.get(i).getId())>0){
                    warehousingList1.get(i).setState(0);
                }else {
                    //出完了
                   warehousingList1.get(i).setState(1);
                }
            }
            return warehousingList1;
        }else {
            for (int i = 0; i < warehousingList1.size(); i++) {
                //证明还有出完
                if (warehousingMapper.selectStateOut(warehousingList1.get(i).getId())>0){
                    warehousingList1.get(i).setState(0);
                }else {
                    //出完了
                    warehousingList1.get(i).setState(1);
                }
            }
            return warehousingList1;
        }

    }

    @Override
    public Warehousing selectOutingById(Long id) {
        Warehousing warehousing = warehousingMapper.selectOutingById(id);
        if (null != warehousing.getPurId()) {
            Purchase purchase = purchaseMapper.selectPurchaseByPurId(warehousing.getPurId());
            warehousing.setProName(purchase.getProName());
            warehousing.setProNumber(purchase.getProNumber());
            return warehousing;
        }
        return warehousing;
    }



    //入库
    @Override
    public int intoWare(IntoWare[] intoWare) {
        if (intoWare.length > 0) {
            String type = intoWare[0].getType();
            //先判断是那种入库
            if (0 == Integer.parseInt(type) || 1 == Integer.parseInt(type)) {
                //甲供/乙购
                for (int i = 0; i < intoWare.length; i++) {
                    PickCondition pickCondition = new PickCondition();
                    IntoWare intoWareMsg = intoWare[i];
                    System.out.println(intoWareMsg + "--------------");
                    //入库
                    PurchaseRecord purchaseRecord = intoWareMsg.getPurchaseRecord();
                    //价格
                    pickCondition.setMd_price(purchaseRecord.getTruePrice());
                    //材料品牌
                    pickCondition.setMdBrand(purchaseRecord.getMdBrand());
                    //材料规格
                    pickCondition.setMdSpecifications(purchaseRecord.getMdSpecifications());
                    //材料供应商
                    pickCondition.setMdBusiness(purchaseRecord.getMdBusiness());
                    //退料
                    if (0 == Integer.parseInt(type)) {
                        //材料来源
                        pickCondition.setMdSupplier(intoWare[0].getProName()+"甲供");
                    }else {
                        //材料来源
                        pickCondition.setMdSupplier(purchaseRecord.getMdBusiness());
                    }
                    //来源类型
                    pickCondition.setMdType(Integer.parseInt(intoWareMsg.getType()));
//                    //去向
//                    pickCondition.setWrWhereabouts(purchaseRecord.getWareName());
                    //数量
                    pickCondition.setPickNum(purchaseRecord.getMdSum());
                    //入库时间
                    pickCondition.setPickDate(purchaseRecord.getInsertTime());
                    //材料外键
                    pickCondition.setmId(purchaseRecord.getmId());
                    //仓库名字
                    pickCondition.setWname(purchaseRecord.getWareName());
                    //仓库Id
                    Long wid = WatehouseMaterialMapper.selectWareIdByName(purchaseRecord.getWareName());
                    pickCondition.setId(wid);
                    pickCondition.setState("1");
                    //入库操作
                    MaterialThree material = new MaterialThree();
                    material.setmId(purchaseRecord.getmId());
                    material.setmName(purchaseRecord.getmName());
                    material.setmModel(purchaseRecord.getmModel());
                    material.setmUnit(purchaseRecord.getmUnit());

                    if (null == WatehouseMaterialMapper.selectMatByname(material.getmName(), material.getmModel())) {
                        //证明材料表中都没有这个材料
                        //材料表中添加新材料，并在关联表中插入新纪录
                        WatehouseMaterialMapper.insertMaterial(material);
                        HashMap<String, Object> hashMap = new HashMap<>();
                        hashMap.put("mId", material.getmId());
                        hashMap.put("wId", wid);
                        WatehouseMaterialMapper.insertMatAndWares(hashMap);

                    } else {
                        //材料表中有这个材料
                        //再去判断中间表中有没有关联
                        MaterialThree materialThree = WatehouseMaterialMapper.selectMatByname(material.getmName(), material.getmModel());
                        HashMap<String, Object> hashMap = new HashMap<>();
                        hashMap.put("mId", materialThree.getmId());
                        hashMap.put("wId", wid);
                        if (WatehouseMaterialMapper.selectMatAndWares(hashMap) != 1) {
                            //插入
                            WatehouseMaterialMapper.insertMatAndWares(hashMap);
                        }

                    }
                    //bug：这里要根据条件查；不能根据mdID查
                    if (1 != WatehouseMaterialMapper.selectMatByMdId(pickCondition.getMdId())) {
                        //是一种新材料的话插入
                        WatehouseMaterialMapper.addMat(pickCondition);
                    } else {
                        //添加数量
                        Double num = pickCondition.getNum();
                        double result = num + pickCondition.getPickNum();
                        HashMap<String, Object> map = new HashMap<>();
                        map.put("result", result);
                        map.put("pickCondition", pickCondition);
                        WatehouseMaterialMapper.addMatSum(map);
                    }

                    //插入一条仓库操作记录
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    String now = simpleDateFormat.format(new Date());
                    pickCondition.setCreateTime(now);
                    int addProRecord = WatehouseMaterialMapper.addWareRecord(pickCondition);
                    Long id = purchaseRecord.getId();
                    HashMap<String, Object> map1 = new HashMap<>();
                    map1.put("id", id);
                    map1.put("insertTime", purchaseRecord.getInsertTime());
                    map1.put("in_mdId", pickCondition.getMdId());
                    map1.put("md_inType", Integer.parseInt(intoWareMsg.getType()));
                    purchaseRecordMapper.updateState(map1);

                }
            } else {
                for (int i = 0; i < intoWare.length; i++) {
                    PickCondition pickCondition = new PickCondition();
                    IntoWare intoWareMsg = intoWare[i];
                    System.out.println(intoWareMsg + "--------------");
                    //入库
                    PurchaseRecord purchaseRecord = intoWareMsg.getPurchaseRecord();
                    //价格
                    pickCondition.setMd_price(purchaseRecord.getTruePrice());
                    //材料品牌
                    pickCondition.setMdBrand(purchaseRecord.getMdBrand());
                    //材料规格
                    pickCondition.setMdSpecifications(purchaseRecord.getMdSpecifications());
                    //材料供应商
                    pickCondition.setMdBusiness(purchaseRecord.getMdBusiness());
                    //材料来源
                    pickCondition.setMdSupplier(purchaseRecord.getMdSupplier());
                    //来源类型
                    pickCondition.setMdType(purchaseRecord.getMdInType());
                    //去向
                    pickCondition.setWrWhereabouts(purchaseRecord.getWareName());
                    //操作数量
                    pickCondition.setPickNum(purchaseRecord.getMdSum());
                    //入库时间
                    pickCondition.setPickDate(purchaseRecord.getInsertTime());
                    //材料外键
                    pickCondition.setmId(purchaseRecord.getmId());
                    //仓库名字
                    pickCondition.setWname(purchaseRecord.getWareName());
                    //仓库Id
                    Long wid = WatehouseMaterialMapper.selectWareIdByName(purchaseRecord.getWareName());
                    pickCondition.setId(wid);
                    //材料明细外键
                    pickCondition.setMdId(purchaseRecord.getInMdId());
                    pickCondition.setState("1");
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    String now = simpleDateFormat.format(new Date());
                    pickCondition.setCreateTime(now);
                    //入库操作

                    //从项目中减去材料 那么有两种情况
                    //第一种 退完了 直接在项目材料明细中将此材料删除
                    //获取材料总量
                    double total = warehousingMapper.selectSum(purchaseRecord.getInMdId());
                    //获取材料领料量
                    double pick = pickCondition.getPickNum();
                    //需要修改的量
                    double pickResultNum = total - pick;
                    //定义变量存结果
                    int b;

                    //没退完 去项目材料修改数量
                    HashMap<String, Object> map = new HashMap();
                    map.put("pickResultNum", pickResultNum);
                    map.put("pickCondition", pickCondition);
                    int update = materialMapper.updateMatSum(map);
                    b = update;


                    //去仓库中加材料
                    //根据仓库名字查仓库id
                    String wname = pickCondition.getWrWhereabouts();
                    Long j = materialMapper.selectWarehouseByWname(wname);
                    pickCondition.setId(j);

                    pickCondition.setMdSupplier(intoWare[i].getProName() + "退");
                    int add = materialMapper.addMat(pickCondition);
                    //先查看这个仓库有没有这种材料
                    HashMap<String, Object> map1 = new HashMap();
                    Long aLong = pickCondition.getmId();
                    map1.put("mId", aLong);
                    map1.put("wId", j);
                    if (materialMapper.selectMat(map1) != 1) {
                        //证明仓库原先没有这种材料
                        materialMapper.insertMat(map1);
                    }
                    //在仓库操作记录中加一条入库记录
                    materialMapper.addWareRecord(pickCondition);
                    //在项目操作中加一条退料记录
                    //将去向改为仓库名字
                    HashMap<String, Object> map2 = new HashMap<>();
                    map2.put("proName", intoWare[i].getProName());
                    map2.put("proNum", intoWare[i].getProNumber());
                    pickCondition.setpId(projectsMapper.selectIdByProName(map2));
                    pickCondition.setWrWhereabouts(purchaseRecord.getWareName());
                    pickCondition.setMdSupplier(null);
                    System.out.println(pickCondition);
                    materialMapper.addProRecord(pickCondition);


                    Long id = purchaseRecord.getId();
                    HashMap<String, Object> map3 = new HashMap<>();
                    map3.put("id", id);
                    map3.put("insertTime", purchaseRecord.getInsertTime());
                    purchaseRecordMapper.updateState(map3);
                }
            }
        }
        return 1;
    }

    //出库
    @Override
    public int outWare(IntoWare[] intoWare) {
        //出库
        for (int i = 0; i < intoWare.length; i++) {
            System.out.println("-----------------------------" + intoWare[i]);
            PickCondition pickCondition = new PickCondition();
            IntoWare intoWareMsg = intoWare[i];
            PurchaseRecord purchaseRecord = intoWareMsg.getPurchaseRecord();
            //价格
            pickCondition.setMd_price(purchaseRecord.getTruePrice());
            //材料品牌
            pickCondition.setMdBrand(purchaseRecord.getMdBrand());
            //材料规格
            pickCondition.setMdSpecifications(purchaseRecord.getMdSpecifications());
            //材料供应商
            pickCondition.setMdBusiness(purchaseRecord.getMdBusiness());
            //材料来源
            pickCondition.setMdSupplier(purchaseRecord.getWareName());
            //来源类型
            pickCondition.setMdType(purchaseRecord.getMdOutType());
            //去向
            pickCondition.setWrWhereabouts(intoWareMsg.getProName());
            //数量
            pickCondition.setPickNum(purchaseRecord.getMdSum());
            //出库时间
            pickCondition.setPickDate(purchaseRecord.getOutTime());
            //材料外键
            pickCondition.setmId(purchaseRecord.getmId());
            //仓库名字
            pickCondition.setWname(purchaseRecord.getWareName());
            //材料外键
            pickCondition.setMdId(purchaseRecord.getOutMdId());

            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String now = simpleDateFormat.format(new Date());
            pickCondition.setCreateTime(now);
            //项目外键
            HashMap<String, Object> map2 = new HashMap<>();
            map2.put("proName", intoWare[i].getProName());
            map2.put("proNum", intoWare[i].getProNumber());
            Long pid = projectsMapper.selectIdByProName(map2);
            pickCondition.setpId(pid);
            //仓库Id
            Long wid = WatehouseMaterialMapper.selectWareIdByName(purchaseRecord.getWareName());
            pickCondition.setId(wid);
            pickCondition.setState("0");
            //出库操作
            //去仓库减去数量
            //获取材料总量
            double total = warehousingMapper.selectSum(purchaseRecord.getOutMdId());
            //获取材料领料量
            double pick = pickCondition.getPickNum();
            //需要修改的量
            double pickResultNum = total - pick;
            HashMap<String, Object> map = new HashMap();
            map.put("pickResultNum", pickResultNum);
            map.put("pickCondition", pickCondition);
            //定义变量存结果
            int b;
            if (pickResultNum == 0) {
                //根据仓库名字查仓库id，将仓库id手动封装到实体类
                String wname = pickCondition.getWname();
                Long j = materialMapper.selectWarehouseByWname(wname);
                pickCondition.setId(j);
                //领完了 去仓库修改数量
//            int delete = materialMapper.deleteByCondition(pickCondition);
                int delete = materialMapper.updateSum(map);
                b = delete;
            } else {
                //没领完 去仓库修改数量

                int update = materialMapper.updateSum(map);
                b = update;
            }
            //判断项目有没有这种材料没有的添加
            MaterialThree materialThree = new MaterialThree();
            materialThree.setmName(purchaseRecord.getmName());
            materialThree.setpId(pid);
            materialThree.setmModel(purchaseRecord.getmModel());
            materialThree.setmUnit(purchaseRecord.getmUnit());
            materialThree.setmId(purchaseRecord.getmId());
            if (materialMapper.selectProjectsMaterial(materialThree) <= 0) {
                materialMapper.insertMaterialproject(materialThree);
            }
            pickCondition.setmName(purchaseRecord.getmName());
            String mName = pickCondition.getmName();

            //判断此种材料是不是电缆
            if (mName.equals("低压电缆") || mName.equals("高压电缆") || mName.equals("控制电缆")) {
                //去项目中加一条材料
                int insertProMat = materialMapper.insertMaterialByCondition(pickCondition);
            } else {
                //不是电缆的话，更新数量
                //先找有没有同种材料
                PickCondition pickCondition1 = materialMapper.selectSameMat(pickCondition);

                if (null == pickCondition1) {
                    //证明项目中没有此种材料直接插入即可
                    pickCondition.setNum(pickCondition.getPickNum());
                    int insertProMat = materialMapper.insertMaterialByCondition(pickCondition);
                } else {
                    //证明材料中已经有了这种材料，修改数量
                    Double pickNum = pickCondition.getPickNum();
                    Double num = pickCondition1.getNum();
                    Double result = num + pickNum;
                    HashMap<String, Object> map1 = new HashMap();
                    map1.put("pickResultNum", result);
                    map1.put("pickCondition", pickCondition1);
                    materialMapper.updateMatSum(map1);
                }

            }


            //从材料操作记录中插入操作记录（领料记录）
            int insertProRec = materialMapper.insertPickRecord(pickCondition);

            //从仓库操作记录中插入数据
            // 根据id查项目名
            Long aLong = pickCondition.getpId();
            String p_name = materialMapper.selectPnameByPid(aLong);
            //将去向改为项目名
            pickCondition.setWrWhereabouts(p_name);

            //根据仓库名字查仓库id
            Long aLong1 = materialMapper.selectWarehouseByWname(pickCondition.getWname());
            pickCondition.setId(aLong1);

            int insertWarRec = materialMapper.outFromWareHouse(pickCondition);


            Long id = purchaseRecord.getId();
            HashMap<String, Object> map1 = new HashMap<>();
            map1.put("id", id);
            map1.put("outTime", purchaseRecord.getOutTime());
            purchaseRecordMapper.updateOutState(map1);

        }
        return 1;
    }


    //删除单条
    @Override
    public int delete(PurchaseRecord purchaseRecord) {
        //先判断是不是采购生成的
        if (warehousingMapper.CountPurId(purchaseRecord.getId()) > 0) {
            //证明不是生成的直接删除
            warehousingMapper.deleteMatByRecId(purchaseRecord.getId());
        } else {
            //如果是生成的话，把状态改成0即可
            if (purchaseRecord.getWarehousingId() != null) {
                warehousingMapper.updateWareId(purchaseRecord);
            }
            if (purchaseRecord.getOutingId() != null) {
                warehousingMapper.updateOutId(purchaseRecord);
            }
        }
        return 1;
    }
}
